package com.byq.mm.smartlib.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;


import com.byq.mm.abstractx.protocol.Defination;
import com.byq.mm.smartlib.R;
import com.byq.mm.smartlib.tools.SimpleDeviceAdapter;

public class OfferActivity extends AbstractSmartActivity {

		Defination defination;
	  @Override
	  public void onCreate(Bundle icicle) {
	    super.onCreate(icicle);
	    defination = (Defination)this.getIntent().getExtras().get("defination");
	    setContentView(R.layout.offer);
	    ImageView deviceIcon = (ImageView)this.findViewById(R.id.deviceIcon);
	    TextView name = (TextView)this.findViewById(R.id.deviceName);
	    TextView id = (TextView)this.findViewById(R.id.deviceId);
	    name.setText(defination.getDevice().getName());
	    id.setText(defination.getDevice().getId());
	    Button accept = (Button)this.findViewById(R.id.accept);

	    Button refuse = (Button)this.findViewById(R.id.refuse);
	    Button aad = (Button)this.findViewById(R.id.acceptanddefine);
	    
	    ListView subdevices = (ListView)this.findViewById(R.id.subdevices);
	    subdevices.setAdapter(new SimpleDeviceAdapter(this,defination.getDevice(), false));

	  
	    accept.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				application.getAndroidSmartEngine().getCoreEngine().getClientDeviceManager().accept(defination);
				finish();
			}
		});
	    refuse.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				application.getAndroidSmartEngine().getCoreEngine().getClientDeviceManager().reject(defination);
				finish();			
			}
		});
	    aad.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				application.getAndroidSmartEngine().getCoreEngine().getClientDeviceManager().acceptAndDefine(defination);
				finish();
			}
		});
	  
	  }
}
